# 求Sn=1!+2!+3!+4!+5!+…+n!之值，其中n是一个数字(n不超过20)。

def factorial(num):
    if num == 0 or num == 1:
        return num
    else:
        return num * factorial(num - 1)


def calculate_factorial_sum(n):
    total_sum = 0
    for i in range(1, n + 1):
        total_sum += factorial(i)
    return total_sum


if __name__ == '__main__':
    n = 5
    result = calculate_factorial_sum(n)
    print(f'当n={n}时,sn的值为{result}')
